package io.renren.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.R;
import io.renren.entity.CCSHistoryEntity;
import io.renren.entity.CCSRecordEntity;
import io.renren.entity.SysUserEntity;
import io.renren.form.CCSRecordForm;
import io.renren.response.CCSRecordResponse;
import io.renren.service.CCSHistoryService;
import io.renren.service.CCSRecordService;
import io.renren.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 选题接口
 * @author SongR
 *
 */
@RestController
@RequestMapping("/api")
@Api(tags = "选题接口")
public class ApiRecordController {
	
	@Autowired
	CCSRecordService rService;
	
	@Autowired
	CCSHistoryService hService;

	@Autowired
	SysUserService uService;
	/**
	 * 添加选题
	 * @return
	 */
	@PostMapping("addRecord")
	@ApiOperation(value = "添加选题",notes="添加选题", response = CCSRecordResponse.class)
	public R addRecord(@ApiParam(name="record",value="选题信息",type="Object",required=true)CCSRecordForm record){
		CCSRecordEntity r = new CCSRecordEntity();
		r.setRecordTitle(record.getTitle());
		r.setRecordAbstracts(record.getAbstracts());
		r.setRecordContent(record.getContent());
		r.setRecordKeys(record.getKeys());
		r.setRecordDominatingfigure(record.getDominatingFigure());
		r.setRecordOccurtime(record.getOccurTime());
		r.setRecordChannelid(record.getChannelId());
		r.setRecordPlaytime(record.getPlayTime());
		r.setRecordImportance(record.getImportance());
		r.setRecordIsinterview(record.getIsInterview());
		r.setRecordAddress(record.getAddress());
		r.setRecordType(record.getTypeId());
		r.setRecordPreassignment(record.getPreAssignment());
		r.setRecordLink(record.getLink());
		r.setRecordOpen(record.getOpen());
		r.setRecordMuser(record.getmUser());
		r.setRecordCuser(record.getcUser());
		r.setRecordCtime(new Date());
		rService.insert(r);
		SysUserEntity user = uService.selectById(r.getRecordCuser());
		CCSHistoryEntity history = new CCSHistoryEntity();
		history.setHistoryExplain(user.getName()==null?user.getUsername():user.getName()+"创建选题");
		history.setHistoryRecord(r.getRecordId());
		history.setHistoryStatus(1);
		history.setHistoryUser(r.getRecordCuser());
		history.setHistoryTime(new Date());
		hService.insert(history);
		return R.ok();
	}
	
	public R updateRecord(){
		
		return R.ok();
	}
	
	
	/**
	 * 搜索选题
	 * @return
	 */
	public R searchRecord(){
		
		return R.ok();
	}
	
	/**
	 * 获取我的选题
	 * @return
	 */
	public R getOwnRecord(){
		
		return R.ok();
	}
	
	
	/**
	 * 获取所有选题 
	 * @return
	 */
	public R getAllRecord(){
		return R.ok();
	}
	
	/**
	 * 待审选题
	 * @return
	 */
	public R waitTrial(){
		return R.ok();
	}
	
	/**
	 * 通过审核
	 * @return
	 */
	public R throughAudit(){
		return R.ok();
	}
	
	
	
	
}
